using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using ViCode_LeVi.Controls.BTBData;
using ViCode_LeVi.Controls.Logs;
using System.Globalization;
using ViCode_LeVi.Data;

namespace ViCode_LeVi.Controls.Reports
{
    public partial class ImportanceTimeSeriesSubReport : DevExpress.XtraReports.UI.XtraReport
    {
        private XRTableCell cellEnd1;
        private XRTableCell cellEnd2;
        private XRTableCell cellEnd3;
        private XRTableCell cellID;
        private XRTableCell cellName;
        private XRTableCell cellStart1;
        private XRTableCell cellStart2;
        private XRTableCell cellStart3;
        private XRTableCell cellValuePeriode1;
        private XRTableCell cellValuePeriode2;
        private XRTableCell cellValuePeriode3;
        private DetailBand DetailImportanceTimeSeriesSubReport;
        private GroupHeaderBand HeaderImportanceTimeSeriesSubReport;
        private PeriodList m_aTimeLinePeriods;
        private XRTable xrTable1;
        private XRTable xrTable2;
        private XRTableCell xrTableCell1;
        private XRTableCell xrTableCell10;
        private XRTableCell xrTableCell13;
        private XRTableCell xrTableCell14;
        private XRTableCell xrTableCell15;
        private XRTableCell xrTableCell2;
        private XRTableCell xrTableCell3;
        private XRTableRow xrTableRow1;
        private XRTableRow xrTableRow2;
        private XRTableRow xrTableRow3;
        private XRTableRow xrTableRow4;

        public ImportanceTimeSeriesSubReport()
        {
            this.InitializeComponent();
        }

        private bool CreateDataBindings()
        {
            bool flag = true;
            try
            {
                this.cellID.DataBindings.Add("Text", base.DataSource, "ID");
                this.cellName.DataBindings.Add("Text", base.DataSource, "FactorName");
                this.cellValuePeriode1.DataBindings.Add("Text", base.DataSource, "ImportancePeriode1");
                this.cellValuePeriode2.DataBindings.Add("Text", base.DataSource, "ImportancePeriode2");
                this.cellValuePeriode3.DataBindings.Add("Text", base.DataSource, "ImportancePeriode3");
            }
            catch (Exception exception)
            {
                flag = false;
                //rsErr = "Fehler in ImportanceTimeSeriesSubReport.CreateDataBindings: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        public bool CreateReport(ref bool bFactors)
        {
            bool flag = true;
            try
            {
                if (this.CreateTableHeader())
                {
                    var data = new ReportDataSourceHelper().GetReportImportanceTimeSeriesList(this.TimeLinePeriods);
                    base.DataSource = data;//
                    if (data .Length> 0)
                    {
                        bFactors = true;
                        return this.CreateDataBindings();
                    }
                    bFactors = false;
                    return flag;
                }
                flag = false;
            }
            catch (Exception exception)
            {
                flag = false;
                //rsErr = "Fehler in ImportanceTimeSeriesSubReport.CreateReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool CreateTableHeader()
        {
            bool flag = true;
            PeriodList timeLinePeriods = this.TimeLinePeriods;
            try
            {
                if (timeLinePeriods != null)
                {
                    switch (timeLinePeriods.Count)
                    {
                        case 1:
                            this.cellStart1.Text = string.Empty;
                            this.cellStart2.Text = string.Empty;
                            this.cellStart3.Text = ((RootData)timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + " -";
                            this.cellEnd1.Text = string.Empty;
                            this.cellEnd2.Text = string.Empty;
                            this.cellEnd3.Text = ((RootData)timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            return flag;

                        case 2:
                            this.cellStart1.Text = string.Empty;
                            this.cellStart2.Text = ((RootData)timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + " -";
                            this.cellStart3.Text = ((RootData)timeLinePeriods[1]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + " -";
                            this.cellEnd1.Text = string.Empty;
                            this.cellEnd2.Text = ((RootData)timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellEnd3.Text = ((RootData)timeLinePeriods[1]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            return flag;

                        case 3:
                            this.cellStart1.Text = ((RootData)timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + " -";
                            this.cellStart2.Text = ((RootData)timeLinePeriods[1]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + " -";
                            this.cellStart3.Text = ((RootData)timeLinePeriods[2]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + " -";
                            this.cellEnd1.Text = ((RootData)timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellEnd2.Text = ((RootData)timeLinePeriods[1]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellEnd3.Text = ((RootData)timeLinePeriods[2]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            return flag;
                    }
                }
            }
            catch (Exception exception)
            {
                flag = false;
                //rsErr = "Fehler in ImportanceTimeSeriesSubReport.CreateTableHeader: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }
        
        public PeriodList TimeLinePeriods
        {
            get
            {
                return this.m_aTimeLinePeriods;
            }
            set
            {
                this.m_aTimeLinePeriods = value;
            }
        }
    }
}
